// 为了显示工作台 静态路由表当成初始值
// 拿到动态路由表之后 再次组合起来 左侧菜单既可以显示静态也可以显示动态

// 解决切换用户有缓存的bug
// 方案：在用户退出登录时 1. 调用清空路由记录的reset方法 2.手动把vuex中的数据也清空 3.把用户信息也清空

import { getProfileAPI } from '@/api/user'
import { routes, resetRouter } from '@/router'
export default {
  namespaced: true,
  state: {
    permission: [],
    menuList: [...routes]
  },
  mutations: {
    setPermission (state, newPermission) {
      state.permission = newPermission
    },
    setMenuList (state, filterRoutes) {
      state.menuList = [...state.menuList, ...filterRoutes]
    },
    // 退出清空路由
    resetRouter (state) {
      resetRouter()
      state.menuList = [...routes]
      state.permission = []
    }
  },
  getters: {},
  actions: {
    async getUserPermission (store) {
      const res = await getProfileAPI()
      console.log(res)
      store.commit('setPermission', res.data.permissions)
      return res.data.permissions
    }
  }
}
